/*
 * @Author: mjjh
 * @LastEditTime: 2023-04-16 19:18:06
 * @FilePath: \chagpt-shuowen\src\store\modules\user\helper.ts
 * @Description:
 */
import * as ss from '@/utils/storage/index.js';

const LOCAL_NAME = 'userStorage'

export interface UserInfo {
  avatar: string
  name: string
  description: string
  id: string
  email: string,
  freeCount:number,//免费次数
  inviteFreeCount:number,//总次数
  level:any,//等级
  levelName:string,//等级名称
  valiDay:string,//剩余多少天到期
  temperature:number//偏好设置
  inviteCode:string,//邀请码
  isBindPhone: boolean,
  endTime: string
}

export interface UserState {
  userInfo: UserInfo
}

export function defaultSetting(): UserState {
  return {
    userInfo: {
      avatar: '',
      name: '卫培AI助手',
      description: '',
      id: '',
      email: '',
      freeCount:0,//
      inviteFreeCount:0,
      level:'',
      levelName:'',
      valiDay:'',
      temperature:0.8,
      inviteCode:'',
      isBindPhone: false,
      endTime: ''
    },
  }
}

export function getLocalState(): UserState {
  const localSetting: UserState | undefined = ss.get(LOCAL_NAME)
  return { ...defaultSetting(), ...localSetting }
}

export function setLocalState(setting: UserState): void {
  ss.set(LOCAL_NAME, setting);
}
